package com.ruoyi.device.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.device.domain.DeviceInfo;
import com.ruoyi.device.service.IDeviceInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 设备类别Controller
 * @auth
 * @date
 */
@RestController
@RequestMapping("/device/deviceInfo")
public class DeviceInfoController extends BaseController {
    @Autowired
    private IDeviceInfoService deviceService;

    /**
     * 查询设备分类列表
     */
    @GetMapping("/list")
    public TableDataInfo list(DeviceInfo params){
        startPage();
        List<DeviceInfo> list = deviceService.getDeviceList(params);
        return getDataTable(list);
    }

    /**
     * 导出设备信息列表
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response , DeviceInfo params){
        List<DeviceInfo> list = deviceService.getDeviceList(params);
        ExcelUtil<DeviceInfo> util = new ExcelUtil<>(DeviceInfo.class);
        util.exportExcel(response, list,"设备信息数据");
    }

    /**
     * 获取设备详细信息
     */
    @GetMapping(value = "/getInfo/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id){
        return success(deviceService.getDeviceById(id));
    }

    /**
     * 新增设备信息
     */
    @PostMapping("/add")
    public AjaxResult add(@RequestBody DeviceInfo device){
        return toAjax(deviceService.addDevice(device));
    }

    /**
     * 修改设备信息
     */
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody DeviceInfo device){
        return toAjax(deviceService.editDevice(device));
    }

    /**
     * 删除设备信息
     */
    @DeleteMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(deviceService.removeDeviceByIds(ids));
    }
}
